SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[WatermanMisc]
@FundID VARCHAR(50),
@NAVDate DATE

AS
BEGIN
SELECT
      CASE
           WHEN dn.NAVShare < 1
           THEN dn.EstNAVShare
           ELSE dn.NAVShare
      END AS NAVPerShare
    
    
    , f.GrossPortVal           AS GrossPFValue
    , f.GAAPYldPurchPrc        AS UnleveredPFYield
    , f.AvailLev               AS TotalFinancingCapacity
    ,(f.LevDrawn)			   AS LeverageStillAvail
    , f.EBITDAAvg              AS AverageEBITDA
    , f.PurchPrc               AS AveragePurchPrice
    , f.AvgMaturity            AS AverageMaturity
    , f.MoodysRating           AS AverageRating
	, f.MktValAssets		   AS FundMarketValue	
	, f.CompCnt				   AS PortfolioCompanies 
 
 
 FROM [FSFundModel].[Reporting].Fund f
      INNER JOIN [FSFundModel].[Reporting].DailyNAV dn
      ON   f.ExportId = dn.ExportId
 
 WHERE f.ExportId =
      (SELECT MAX(e.ExportId)
      FROM [FSFundModel].[Reporting].Export e
      WHERE e.FundId = @FundID
      AND  e.NAVDate = @NAVDate)
 AND  dn.DailyNAVStatusType = 'Today'
END

GO
EXEC sp_addextendedproperty N'VirtualFolder', N'Live/CharlieWaterman', 'SCHEMA', N'dbo', 'PROCEDURE', N'WatermanMisc', NULL, NULL
GO
